<?php

namespace App\Listeners;

use App\model\user\UserSocialite;
use App\Repository\UserRepository;
use Overtrue\LaravelWeChat\Events\WeChatUserAuthorized;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;

class WeChatUserAuthorizedListener
{
    protected  $userRepository;
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct(UserRepository $userRepository)
    {
        $this->userRepository=$userRepository;
    }

    /**
     * Handle the event.
     *
     * @param  WeChatUserAuthorized  $event
     * @return void
     */
    public function handle(WeChatUserAuthorized $event)
    {
        $this->userRepository->socialiteLogin([
            'openid'=>$event->user->getId(),
            'nickname'=>$event->user->getNickname(),
            'avatar'=>$event->user->getAvatar(),
            'type'=>UserSocialite::WECHAT
        ]);



    }
}
